﻿@model IEnumerable<SQLInstance.DatabaseIndex>
@{
    var indexes = Model.ToList();
}
@if (indexes.Count > 0)
{
    <div class="panel panel-default text-wrap">
        <div class="panel-heading">
            <h6>@indexes.Count.Pluralize("Index")</h6>
        </div>
        <div class="panel-body">
            <div class="list-group list-group-sm">
                @foreach (var index in indexes.OrderByDescending(i => i.IsPrimaryKey).ThenBy(i => i.IndexName))
                {
                    <div class="list-group-item">
                        <div>
                            @if (index.IsPrimaryKey)
                            {
                                <i class="fa fa-key fa-fw text-warning" aria-hidden="true" title="Primary Key"></i>
                            }
                            else
                            {
                                <i class="fa fa-list-alt fa-fw" aria-hidden="true"></i>
                            }
                            @index.IndexName
                            <span class="text-muted">(@index.IndexType@(index.IsUnique ? ", Unique" : null)@(index.IsFiltered ? ", Filtered" : null))</span>
                        </div>
                        <div>
                            <span class="text-muted">Columns:</span> @(index.KeyDefinition?.Replace("[","").Replace("]",""))
                        </div>
                        @if (index.IncludeDefinition.HasValue())
                        {
                            <div>
                                <span class="text-muted">Included:</span> @(index.IncludeDefinition?.Replace("[", "").Replace("]", ""))
                            </div>
                        }
                        @if (index.IsFiltered)
                        {
                            <div>
                                <span class="text-muted">Filter:</span> @(index.FilterDefinition?.Replace("[", "").Replace("]", ""))
                            </div>
                        }
                        @if (index.StatsLastUpdated.HasValue)
                        {
                            <div>
                                <span class="text-muted">Last Stats Rebuild:</span> @index.StatsLastUpdated.Value.ToRelativeTimeSpan()
                            </div>
                        }
                    </div>
                }
            </div>
        </div>
    </div>
}